<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta
        http-equiv="Content-Type"
        content="text/html; charset=utf-8"
    />
    <title>1 boxs</title>

    <style>
        html,
        body {
            overflow: hidden;
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
        }

        #renderCanvas {
            width: 100%;
            height: 100%;
            touch-action: none;
        }
    </style>

    <script src="https://cdn.babylonjs.com/babylon.js"></script>
    <!-- 允许您将模型导入到场景中 -->
    <script src="https://cdn.babylonjs.com/loaders/babylonjs.loaders.min.js"></script>
    <!-- 允许您使用触摸屏 -->
    <script src="https://code.jquery.com/pep/0.4.3/pep.js"></script>
</head>

<body>
    <canvas
        id="renderCanvas"
        touch-action="none"
    ></canvas>
    <!-- 注意browseatouch-action="none"以获得PEPr/canvas调整大小事件的最佳效果 -->
    

    <script>
        const canvas = document.getElementById("renderCanvas"); //获取canvas元素
        const engine = new BABYLON.Engine(canvas, true); // Generate the BABYLON 3D engine

        //在这里添加与playground格式匹配的代码
        const createScene = function () {
            const scene = new BABYLON.Scene(engine);//使用引擎
            const camera = new BABYLON.ArcRotateCamera("camera", -Math.PI / 2, Math.PI / 2.5, 15, new BABYLON.Vector3(0, 0, 0));//设置摄像机
            camera.attachControl(canvas, true);
            const light = new BABYLON.HemisphericLight("light", new BABYLON.Vector3(1, 1, 0));//设置灯光

            // 定义两个盒子会导致重叠，暂时关闭一个
            // BABYLON.SceneLoader.ImportMeshAsync("", "https://assets.babylonjs.com/meshes/", "box.babylon")//导入盒子模型
            // const box1 = BABYLON.MeshBuilder.CreateBox("box1", {});//定义盒子
            // box1.position.y = 0.5;//设置box的y轴高度
            //添加地面
            const ground = BABYLON.MeshBuilder.CreateGround("ground", { width: 10, height: 10 });

            // // 导入声音，每三秒重播一次
            // const bounce = new BABYLON.Sound("bounce", "F:/VScode/babylonjs/babylon-demo1/src/Fool_For_You.mp4", scene);
            // setInterval(() => bounce.play(), 3000);

            const music = new BABYLON.Sound("Fool_For_You", "F:/VScode/babylonjs/babylon-demo1/src/Fool_For_You.mp4", scene, null, { loop: true, autoplay: true });

            //三种导入盒子并设置大小
            const box2 = BABYLON.MeshBuilder.CreateBox("box2", { width: 2, height: 1.5, depth: 3 })
            const box3 = BABYLON.MeshBuilder.CreateBox("box3", {}); //unit cube
            box3.scaling.x = 1.5;
            box3.scaling.y = 6.5;
            box3.scaling.z = 2;
            const box4 = BABYLON.MeshBuilder.CreateBox("box4", {}); //unit cube
            box4.scaling = new BABYLON.Vector3(4, 0.5, 3.8);
            box4.position.y = 3.5
            //沿y轴旋转操作
            box4.rotation.y = Math.PI / 4;
            box4.rotation.x = Math.PI / 4;


            return scene;

        }
        const scene = createScene(); //调用createScene函数

        //注册一个渲染循环来重复渲染场景
        engine.runRenderLoop(function () {
            scene.render();
        });

        // 注意浏览器、画布大小调整事件
        window.addEventListener("resize", function () {
            engine.resize();
        });
    </script>
</body>

</html>